<?php

(defined('_VALID_MOS') OR defined('_JEXEC')) or die('Direct Access to this location is not allowed xxx.');

//Globals definition
$GLOBALS['jDFPitemid'] = jd_CalcItemid();
$GLOBALS['jDFPOnlineLayout'] = '';
$GLOBALS['jlistConfigM'] = buildjlistConfigM();
$GLOBALS['YfilesMessage'] = 0;
$GLOBALS['YfilesTested'] = 0;
$GLOBALS['YfilesInstalled'] = 0;
$GLOBALS['YfilesVersion'] = 0;
$GLOBALS['jDFPshowunpublished'] = 0;
$GLOBALS['jDFPconsiderrights'] = 1;
$GLOBALS['jDFPv14'] = 0;
$GLOBALS['jDFPsfolders'] = jd_SymbolFolders();
$GLOBALS['jDFPpluginversion'] = '1.4 twin4f';
$GLOBALS['jDFPrank'] = 1;
$GLOBALS['jDFPison'] = 1;
$GLOBALS['jDFPcatids'] = '';
$GLOBALS['jDFPloaded'] = 0;

  // Register the plugin
  $_MAMBOTS->registerFunction( 'onPrepareContent', 'mos_yfiles_file10' );

  global $_VERSION, $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_lang;

  // Language-file of plugin
  if (file_exists($mosConfig_absolute_path.'/mambots/content/mos_yfiles_file/languages/'.$mosConfig_lang.'.php')) {
     include($mosConfig_absolute_path.'/mambots/content/mos_yfiles_file/languages/'.$mosConfig_lang.'.php');
  } else {
     include($mosConfig_absolute_path.'/mambots/content/mos_yfiles_file/languages/english.php');
  }

  // Language-file of jDownload-component
  if (file_exists($mosConfig_absolute_path.'/components/com_yfiles/languages/'.$mosConfig_lang.'.php')) {
     include($mosConfig_absolute_path.'/components/com_yfiles/languages/'.$mosConfig_lang.'.php');
  } else {
     include($mosConfig_absolute_path.'/components/com_yfiles/languages/russian.php');
  }
  $GLOBALS['jDFP_JLanguage'] = $mosConfig_lang;

  // Live site
  $GLOBALS['jDFPlive_site'] = $mosConfig_live_site;

  // Live site of plugin
  $GLOBALS['jDFPplugin_live_site'] = $mosConfig_live_site."/".'mambots/';

  // Absolute path
  $GLOBALS['jDFPabsolute_path'] = $mosConfig_absolute_path."/";

  // Joomla version
 // $GLOBALS['jDFP_JVersion'] = $_VERSION->PRODUCT." ".$_VERSION->RELEASE.".".$_VERSION->DEV_LEVEL." " .$_VERSION->DEV_STATUS." " .$_VERSION->CODENAME;


// Get database
function &getDBO()
{

  static $instance;
  if (!is_object($instance)) {
   
      global $database;
      $instance = $database;
   
  }
  return $instance;
}

// Calculate ItemID of Yfiles-component
function jd_CalcItemid()
{
    $database = getDBO();
    $database->setQuery("SELECT id from #__menu WHERE link = 'index.php?option=com_yfiles'");
    $l_Itemid = $database->loadResult();
    if (!$l_Itemid) $l_Itemid = 999999;
    return $l_Itemid;
}

// Calculate Symbolfolders depending on Yfiles 1.3 and 1.4 and set global Yfiles version 1.4 or <= 1.3
function jd_SymbolFolders(){
   global $jlistConfigM, $jDFPv14, $mosConfig_live_site;
   $jDFPv14 = 0;
   $jd_l_folders = array();
   $jd_l_folders['symbolfolder'] = 'components/com_yfiles/';
   $jd_l_folders['cat'] = 'components/com_yfiles/catimages/';
   $jd_l_folders['download'] = 'components/com_yfiles/images/';
   $jd_l_folders['file'] = 'components/com_yfiles/fileimages/';
   $jd_l_folders['hot'] = 'components/com_yfiles/images/';
   $jd_l_folders['mini'] = 'components/com_yfiles/images/';
   $jd_l_folders['new'] = 'components/com_yfiles/images/';
   $jd_l_folders['upd'] = 'components/com_yfiles/images/';
   $jd_l_folders['thumb'] = 'images/yfiles/screenshots/thumbnails/';
   $jd_l_folders['screenshot'] = 'images/yfiles/screenshots/';
   $jDiVersion = substr($jlistConfigM['jd.version'],0,3);
   if (($jDiVersion >= 1.0) || ($jlistConfigM['jd.version.svn'] >= 555)){
     $jDFPv14 = 1;
     $jd_l_folders['symbolfolder'] = 'images/yfiles/';
     $jd_l_folders['cat'] = 'images/yfiles/catimages/';
     $jd_l_folders['download'] = 'images/yfiles/downloadimages/';
     $jd_l_folders['file'] = 'images/yfiles/fileimages/';
     $jd_l_folders['hot'] = 'images/yfiles/hotimages/';
     $jd_l_folders['mini'] = 'images/yfiles/miniimages/';
     $jd_l_folders['new'] = 'images/yfiles/newimages/';
     $jd_l_folders['upd'] = 'images/yfiles/updimages/';
   }
   return $jd_l_folders;
}

function jd_checkAccess(){
  global $jDFPconsiderrights;
  if ($jDFPconsiderrights == 0){
    $access = '22';
    return $access;
  }
     global $my;
    $GidAid = $my->gid;
  
  $access = '';
  if ($GidAid == 0) $access = '01';
  if ($GidAid == 1) $access = '11';
  if ($GidAid == 2) $access = '22';
  return $access;
}

function jd_emailcloak($p_email, $p_author){


    return mosHTML::emailcloaking($p_email, true, $p_author, false);
 
 
}

function jd_SefRel($p_Url){
 
 
    return sefRelToAbs($p_Url);
 
}

function jd_DateForm($p_Date){
  global $jlistConfigM;
 
    return mosFormatDate($p_Date, $jlistConfigM['global.datetime'], $offset = NULL);
 
}

// Read configuration of Yfiles from database
function buildjlistConfigM(){
  global $jDFPOnlineLayout;
  $database = getDBO();
  $jlistConfig = array();
  $database->setQuery("SELECT setting_name, setting_value FROM #__yfiles_config");
  $jlistConfigObj = $database->loadObjectList();
  if(!empty($jlistConfigObj)){
    foreach ($jlistConfigObj as $jlistConfigRow){
      $jlistConfig[$jlistConfigRow->setting_name] = $jlistConfigRow->setting_value;
    }
    if (!$jlistConfig['days.is.file.updated']){
      $jlistConfig['days.is.file.updated'] = 0;
    }
    if (!$jlistConfig['jd.version.svn']){
      $jlistConfig['jd.version.svn'] = 0;
    }
  }
  if ($jDFPOnlineLayout == '') {
    $jDFPOnlineLayout = $jlistConfig['fileplugin.defaultlayout'];
  }
  return $jlistConfig;
}

function DatumsDifferenz_JDm($Start,$Ende) {
    $Tag1=(int) substr($Start, 8, 2);
    $Monat1=(int) substr($Start, 5, 2);
    $Jahr1=(int) substr($Start, 0, 4);

    $Tag2=(int) substr($Ende, 8, 2);
    $Monat2=(int) substr($Ende, 5, 2);
    $Jahr2=(int) substr($Ende, 0, 4);

    if (checkdate($Monat1, $Tag1, $Jahr1)and checkdate($Monat2, $Tag2, $Jahr2)){
        $Datum1=mktime(0,0,0,$Monat1, $Tag1, $Jahr1);
        $Datum2=mktime(0,0,0,$Monat2, $Tag2, $Jahr2);

        $Diff=(Integer) (($Datum1-$Datum2)/3600/24);
        return $Diff;
    } else {
        return -1;
    }
}


function mos_yfiles_file10( $published, $row, $params, $page ) {
	global $mainframe, $jDFPplugin_live_site, $jDFPloaded, $mosConfig_live_site;

if ($jDFPloaded == 0)
{
   $mainframe->addCustomHeadTag('<script src="'.$mosConfig_live_site.'/components/com_yfiles/yfiles.js" type="text/javascript"></script>');
$mainframe->addCustomHeadTag('<script src="'.$mosConfig_live_site.'/components/com_yfiles/lightbox/lightbox.js" type="text/javascript"></script>');

$mainframe->addCustomHeadTag( "<link href=\"".$mosConfig_live_site."/components/com_yfiles/yfiles_fe.css\" rel=\"stylesheet\" type=\"text/css\"/>" );
$mainframe->addCustomHeadTag( "<link href=\"".$mosConfig_live_site."/components/com_yfiles/lightbox/lightbox.css\" rel=\"stylesheet\" type=\"text/css\"/>" );
?>
   
<?php
}
  $jDFPloaded = 1;
  if (isset( $_GET['mjdfpp'])){
    if ($_GET['mjdfpp'] == 'show'){
       $row->text = jd_file_parameters().$row->text;
       return true;
    }
  }
  $regex = "#{jd_file (.*?)==(.*?)}#s";
  $row->text = preg_replace_callback($regex, "jd_file_callback", $row->text);

  return true;
}


function jd_file_callback($matches){
  global $YfilesTested, $YfilesMessage, $YfilesInstalled, $YfilesVersion, $jlistConfigM, $jDFPOnlineLayout, $jDFPrank, $jDFPison;
  $database = getDBO();
  $jdf_whatcontent = $matches[1];

  if ($jdf_whatcontent == 'plugin'){
     switch ($matches[2]){
	 case 'on':
       $jDFPison = 1;
       break;
	 case 'off':
       $jDFPison = 0;
       break;
	 case 'silent':
       $jDFPison = 2;
       break;
     }
     return '';
  }
  if ($jDFPison == 0){
	return $matches[0];
  }
  if ($jDFPison == 2){
	return '';
  }

  // Tester si Yfiles >= 1.3 installй.
  if ($YfilesTested == 0) {
    $YfilesTested = true;
    $comSQLquery = "SELECT * FROM #__components WHERE (parent = 0) AND (`option` = 'com_yfiles')";
    $database->setQuery( $comSQLquery );
    $comrows = $database->loadObjectList();
    if (!$comrows) {
      $YfilesInstalled = 0;
    } else {
      $YfilesInstalled = 1;
      $jDiVersion = substr($jlistConfigM['jd.version'],0,3);
      if (($jDiVersion == 1.3) || ($jDiVersion == 1.0)) {
        $YfilesVersion = 1;
      } else {
        $YfilesVersion = 0;
      }
    }
  }

  // sinon message d'erreur (1 fois) et abandon du programme.
  if ($YfilesInstalled == 0) {
    if ($jdf_whatcontent != 'mjdfpp') {
      if ($YfilesMessage == 0){
        $YfilesMessage = 1;
        return _JDPLUGIN_FRONTEND_JDOWNLOADS_NOTINSTALLED;
      } else {
        return "";
      }
    }
  } else {
    if ($YfilesVersion == 0) {
      if ($jdf_whatcontent != 'mjdfpp') {
        if ($YfilesMessage == 0){
          $YfilesMessage = 1;
          return _JDPLUGIN_FRONTEND_JDOWNLOADS_WRONGVERSION ;
        } else {
          return "";
        }
      }
    }
  }

  // Layouts laden
  if ($jDFPOnlineLayout == '') {
    $jDFPOnlineLayout = $jlistConfigM['fileplugin.defaultlayout'];
  }

  switch ($jdf_whatcontent) {
    case 'file':
      $jDFPrank = '';
      $id_result = jd_file_createdownload($matches);
      break;
    case 'durl':
      $jDFPrank = '';
      $id_result = jd_file_createdownload($matches);
      break;
    case 'mjdfpp':
      $id_result = jd_file_parameters();
      break;
    case 'onlinelayout':
      jd_set_newlayout($matches);
      $id_result = '';
      break;
    case 'latest':
      $id_result =jd_file_latest_hottest($matches);
      break;
    case 'hottest':
      $id_result = jd_file_latest_hottest($matches);
      break;
    case 'considerrights':
      $id_result = jd_file_changerights($matches);
      break;
    case 'showunpublished':
      $id_result = jd_file_changeunpublished($matches);
      break;
    }
  return $id_result;
}

function jd_file_changerights($matches){
	global $jDFPconsiderrights;
    if ($matches[2] == 'off'){
       $jDFPconsiderrights = 0;
    }
    if ($matches[2] == 'on'){
       $jDFPconsiderrights = 1;
    }
}

function jd_file_changeunpublished($matches){
	global $jDFPshowunpublished;
    if ($matches[2] == 'off'){
       $jDFPshowunpublished = 0;
    }
    if ($matches[2] == 'on'){
       $jDFPshowunpublished = 1;
    }
}

function jd_file_parameters (){
  global $jlistConfigM, $jDFPshowunpublished, $jDFPOnlineLayout, $jDFPpluginversion, $jDFPsfolders, $jDFPabsolute_path, $jDFPplugin_live_site, $jDFP_JVersion, $jDFP_JLanguage, $jDFPitemid, $jDFPloaded, $jDFPv14;
  $database = getDBO();
  //$jconfig = JFactory::getConfig();
  //echo $jconfig->getValue("config.db");

  $showConfig = "";
  $mytdleft = '<tr><td class="jdpf_parameters_l">';
  $mytdmiddle = '</td><td class="jdpf_parameters_r">';
  $mytdright = '</td></tr>';
  $mytdlefth = '<tr><td class="jdpf_parameters_title_l">';
  $mytdmiddleh = '</td><td class="jdpf_parameters_title_r">';
  $mytdrighth = '</td></tr>';
  $showConfig .= '<table class="jdpf_parameters">';
  $showConfig .= '<tr><td colspan=2 class="jdpf_parameters_header"> Current Plugin-Parameters for mos_yfiles_file:</td></tr>';
  $showConfig .= $mytdlefth."Параметр".$mytdmiddleh."Значение".$mytdrighth;
  $showConfig .= $mytdleft."Язык".$jDFP_JLanguage.$mytdright;
  $showConfig .= $mytdleft."Версия плагина".$mytdmiddle.$jDFPpluginversion.$mytdright;
  $showConfig .= $mytdleft."jd.version".$mytdmiddle.$jlistConfigM['jd.version']." (".$jlistConfigM['jd.version.state']." SVN:".$jlistConfigM['jd.version.svn'].")".$mytdright;
  $showConfig .= $mytdleft."Flag is v14".$mytdmiddle.$jDFPv14.$mytdright;
  $showConfig .= $mytdleft."Префикс".$mytdmiddle.$database->getPrefix().$mytdright;
  $showConfig .= $mytdleft."Абсолютный путь".$mytdmiddle.$jDFPabsolute_path.$mytdright;
  $showConfig .= $mytdleft."Относительный путь к плагину".$mytdmiddle.$jDFPplugin_live_site.$mytdright;
  $showConfig .= $mytdleft."ItemID".$mytdmiddle.$jDFPitemid.$mytdright;
  $showConfig .= $mytdleft."Загрузка".$mytdmiddle.$jDFPloaded.$mytdright;
  $showConfig .= $mytdleft."Папка компонента".$mytdmiddle.$jDFPsfolders['symbolfolder']."...".$mytdright;

  $database->setQuery("SELECT setting_name, setting_value FROM #__yfiles_config WHERE setting_name LIKE 'fileplugin%'");
  $jlistConfigObj = $database->loadObjectList();
  if(!empty($jlistConfigObj)){
    foreach ($jlistConfigObj as $jlistConfigRow){
      $s_value = $jlistConfigRow->setting_value;
      if (($jlistConfigRow->setting_name == 'fileplugin.layout_disabled') || ($jlistConfigRow->setting_name == 'fileplugin.show_hot') || ($jlistConfigRow->setting_name == 'fileplugin.show_new')){
        $s_value .= '&nbsp;&nbsp;<font color="#000088">(Notice: Obsolete since 1.4)</font>';
      }

      $showConfig .= $mytdleft.$jlistConfigRow->setting_name.$mytdmiddle.$s_value.$mytdright;
    }
  } else {
    $showConfig .= $mytdleft."Database error".$mytdmiddle."Datbase yfiles_config missing!".$mytright;
  }
  $showConfig .= $mytdleft."Access level".$mytdmiddle.jd_checkAccess().$mytdright;
  $showConfig .= $mytdleft."Show unpublished".$mytdmiddle.$jDFPshowunpublished.$mytdright;
  $showConfig .= $mytdleft."&nbsp;".$mytdmiddle."&nbsp;".$mytdright;

  $tSQLquery = "SELECT * FROM #__yfiles_templates WHERE (template_name = '".$jDFPOnlineLayout."') AND (template_typ = 2)";
  $database->setQuery($tSQLquery);
  $onlrows = $database->loadObjectList();
  if (!$onlrows) {
    $OnlineLayoutComment = '<font color="#FF0000"> MISSING !</font>';
  }
  else{
    $OnlineLayoutComment = '<font color="#008800"> AVAILABLE !</font>';
  }
  $showConfig .= $mytdlefth."Layout online".$mytdmiddleh."&quot;".$jDFPOnlineLayout."&quot;".$OnlineLayoutComment.$mytdrighth;
  $onltext = $onlrows[0]->template_text;
  $showConfig .= $mytdleft."Layout online text".$mytdmiddle.'<textarea cols="45" rows="5">'.$onltext."</textarea>".$mytdright;
  $showConfig .= '</table>';
  return $showConfig;
}

function jd_set_newlayout($matches){
  global $jDFPOnlineLayout;
  $jDFPOnlineLayout = $matches[2];
  return '';
}

function inh_rights($pcatid){
    $database = getDBO();
    $sql = "SELECT cat_id, parent_id, cat_access FROM #__yfiles_cats WHERE cat_id = ".$pcatid;
    $database->setQuery($sql);
    $crow = $database->loadObjectList();
    if (!$crow){
	  return '00';
    }
    if ($crow[0]->parent_id == 0){
	  return $crow[0]->cat_access;
    }
    $therights = $crow[0]->cat_access;

    while ( $crow[0]->parent_id > 0 ){
      $sql = "SELECT cat_id, parent_id, cat_access FROM #__yfiles_cats WHERE cat_id = ".$crow[0]->parent_id;
      $database->setQuery($sql);
      $crow = $database->loadObjectList();
      if ($crow[0]->cat_access > $therights){
      	$therights = $crow[0]->cat_access;
	  }
    }
    return $therights;
}

function inh_published($pcatid){
    $database = getDBO();
    $sql = "SELECT cat_id, parent_id, published FROM #__yfiles_cats WHERE cat_id = ".$pcatid;
    $database->setQuery($sql);
    $crow = $database->loadObjectList();
    if (!$crow){
	  return '1';
    }
    if ($crow[0]->parent_id == 0){
	  return $crow[0]->published;
    }
    $therights = $crow[0]->published;

    while ( $crow[0]->parent_id > 0 ){
      $sql = "SELECT cat_id, parent_id, published FROM #__yfiles_cats WHERE cat_id = ".$crow[0]->parent_id;
      $database->setQuery($sql);
      $crow = $database->loadObjectList();
      if ($crow[0]->published < $therights){
      	$therights = $crow[0]->published;
	  }
    }
    return $therights;
}

function inh_published_file($filepublish, $pcatid){
   $catpublish = inh_published($pcatid);
   if ($catpublish < $filepublish){
	return $catpublish;
   }
   else{
	return $filepublish;
   }
}

function get_catids($p_subcat){
  global $jDFPcatids, $jDFPshowunpublished, $jDFPconsiderrights;
  $database = getDBO();
  $access = jd_checkAccess();
  $sql = "SELECT * FROM #__yfiles_cats WHERE parent_id = ".$p_subcat." {pppp}{rrrr}ORDER BY ordering";
  if ($jDFPshowunpublished == 0){
    $sql = str_replace('{pppp}','AND published = 1 ',$sql);
  }
  else{
    $sql = str_replace('{pppp}','',$sql);
  }
  if ($jDFPconsiderrights == 0){
    $sql = str_replace('{rrrr}','',$sql);
  }
  else{
    $sql = str_replace('{rrrr}','AND cat_access <= '.$access.' ',$sql);
  }
  $database->setQuery($sql);
  $frows = $database->loadObjectList();
  if (!$frows){
  	return false;
  }
  foreach ($frows as $therow){
    $jDFPcatids .= $therow->cat_id.',';
  	get_catids($therow->cat_id);
  }
  return '';
}

function jd_file_latest_hottest($matches){
   global $jDFPshowunpublished, $jDFPrank, $jDFPcatids;
   $database = getDBO();

   $jDFPcatids = '';
   $bidon = get_catids(0);

   $filesql = "SELECT file_id FROM #__yfiles_files WHERE {xxxx}cat_id IN (".substr($jDFPcatids,0,-1).") ORDER BY {dado} DESC LIMIT ".$matches[2].";";
   if ($matches[1] == 'latest'){
     $filesql = str_replace("{dado}",'date_added',$filesql);
   }
   else{
     $filesql = str_replace("{dado}",'downloads',$filesql);
   }

   if ($jDFPshowunpublished == 1){
      $filesql = str_replace("{xxxx}",'',$filesql);
   }
   else{
      $filesql = str_replace("{xxxx}",'published = 1 AND ',$filesql);
   }

   $database->setQuery($filesql);
   $files = $database->loadObjectList();
   $filetable = '';
   $jDFPrank = 1;
   if ($files){
   	foreach ($files as $thefile){
   		$sim_matches = array("", "file", $thefile->file_id);
        $filetable .= jd_file_createdownload($sim_matches);
        $jDFPrank++;
   	}
   }
   return $filetable;
}

function jd_file_createdownload($matches){
  global $jlistConfigM, $jDFPitemid, $jDFPOnlineLayout, $jDFPshowunpublished, $jDFPsfolders;
  $database = getDBO();

  // Chercher Layout dans la bd
  $jdLayout = $jDFPOnlineLayout;
  $tSQLquery = "SELECT * FROM #__yfiles_templates WHERE (template_name = '".$jdLayout."') AND (template_typ = 2)";
  $database->setQuery($tSQLquery);
  $trows = $database->loadObjectList();

  // Tester si le layout existe, sinon message d'erreur.
  if (!$trows) {
    $ReturnValue = str_replace("{thelayout}",$jdLayout,_JLIST_FRONTEND_SETTINGS_FILEPLUGIN_LAYOUTUNKNOWN).'<br />';
     return $ReturnValue;
  }

  $jd_template = $trows[0]->template_text;
  $jd_template_symbol_off = $trows[0]->symbol_off;

  //Chercher LE fichier selon ID dans Mambot
  $fSQLquery = "SELECT * FROM #__yfiles_files WHERE file_id = ".$matches[2];
  $database->setQuery($fSQLquery);
  $frows = $database->loadObjectList();
  if (!$frows){
    $fSQLquery = "SELECT * FROM #__yfiles_files WHERE file_title = '".$matches[2]."'";
    $database->setQuery($fSQLquery);
    $frows = $database->loadObjectList();
  }

  if (!$frows) {
    $jd_filepic = '/plugins/content/mos_yfiles_file/images/offline.gif';
    $jd_filetitle = str_replace("{fileid}",$matches[2],_JLIST_FRONTEND_SETTINGS_FILEPLUGIN_FILEUNKNOWN);
    $jd_template = jd_file_fill_nodownload($jd_template,$jd_filetitle,'',$jd_filepic);
    if ($jlistConfigM['fileplugin.enable_plugin'] == 0) {
    	if ($jlistConfigM['fileplugin.show_jdfiledisabled'] == 0){
          $jd_template = '';
    	}
      }
    return $jd_template;
  }
  // Quitter si le fichier n'est pas publiй et que l'affichage des fichier non-publiйs est dйsactivй
  if ($jDFPshowunpublished == 0){
     $l_fpublished = inh_published_file($frows[0]->published, $frows[0]->cat_id);
     if ($l_fpublished == 0){
       return "";
     }
  }

  // Chercher la catйgorie pour voir si visiteur a des droits sur le fichier
  $l_frights = inh_rights($frows[0]->cat_id);

  // Calculer si le visiteur peut voir le fichier
  $user_download_access = jd_checkAccess();
  if ($user_download_access < $l_frights){
  	return "";
  }

  // Calculer si le visiteur peut tйlйcharger
  $user_download_access = (int)substr($user_download_access,0,1);
  $file_download_access = (int)substr($l_frights,1,1);
  $jd_dallowed = 0;
  if ($file_download_access <= $user_download_access){
	$jd_dallowed = 1;
  }

  // Plugin enabled or disabled
  if ($jlistConfigM['fileplugin.enable_plugin'] == 0){
    if ($jlistConfigM['fileplugin.show_jdfiledisabled'] == 0){
      $jd_template = '';
    } else {
        $jd_filetitle = $jlistConfigM['fileplugin.offline_title'];
        $jd_filepic = '/plugins/content/mos_yfiles_file/images/offline.gif';
        $jd_filedescription = $jlistConfigM['fileplugin.offline_descr'];
        if ($jlistConfigM['fileplugin.show_downloadtitle'] == 1){
          $jd_filetitle = $frows[0]->file_title;
          $jd_filepic = $jDFPsfolders['file'].$frows[0]->file_pic;
          $jd_filedescription = $jlistConfigM['fileplugin.offline_title'].'&nbsp;'.$jlistConfigM['fileplugin.offline_descr'];
        }
        $jd_template = jd_file_fill_nodownload($jd_template,$jd_filetitle,$jd_filedescription,$jd_filepic);
    }
    return $jd_template;
  }

  $jd_template = jd_file_fill_downloadok($jd_template, $frows[0], $jd_template_symbol_off, $matches[1], $jd_dallowed);

  return $jd_template;
}

function jd_file_fill_nodownload($p_Template, $p_Title, $p_Description, $p_Filepic){
  global $jlistConfigM, $jDFPitemid, $jDFPplugin_live_site, $jDFPlive_site;

  $l_Template = str_replace("{{{","[[[",$p_Template);
  $jd_file_pic = '<img src="'.$jDFPlive_site.$p_Filepic.'" align="absmiddle" border="0" height="'.$jlistConfigM['file.pic.size'].'" width="'.$jlistConfigM['file.pic.size'].'" alt="" />';
  $l_Template = str_replace("{file_pic}",$jd_file_pic,$l_Template);
  $jd_file_pic = '<img src="'.$jDFPplugin_live_site.'content/mos_yfiles_file/images/nodownload.gif">';
  $l_Template = str_replace("{checkbox_list}",$jd_file_pic,$l_Template);
  $l_Template = str_replace("{file_title}",$p_Title,$l_Template);
  $l_Template = str_replace("{file_title_only}",$p_Title,$l_Template);
  $l_Template = str_replace("{description}",$p_Description,$l_Template);
  $l_Template = str_replace("{release}",'',$l_Template);
  $l_Template = str_replace("{size}",'',$l_Template);
  $l_Template = str_replace("{downloads}",'',$l_Template);
  $l_Template = str_replace("{pic_is_new}",'',$l_Template);
  $l_Template = str_replace("{pic_is_hot}",'',$l_Template);
  $l_Template = str_replace("{license}",'',$l_Template);
  $l_Template = str_replace("{date_added}",'',$l_Template);
  $l_Template = str_replace("{language}",'',$l_Template);
  $l_Template = str_replace("{system}",'',$l_Template);
  $l_Template = str_replace("{url_download}",'',$l_Template);
  $l_Template = str_replace("{file_id}",'',$l_Template);
  $l_Template = str_replace("{ordering}",'',$l_Template);
  $l_Template = str_replace("{published}",'',$l_Template);
  $l_Template = str_replace("{cat_id}",'',$l_Template);
  $l_Template = str_replace("{mirror_1}",'',$l_Template);
  $l_Template = str_replace("{mirror_2}",'',$l_Template);
  $l_Template = str_replace("{link_to_details}",'',$l_Template);
  $l_Template = str_replace("{thumbnail}",'',$l_Template);
  $l_Template = str_replace("{screenshot}",'',$l_Template);
  $l_Template = str_replace("{pic_is_updated}",'',$l_Template);
  $l_Template = str_replace("{rank}",'',$l_Template);

  $l_Template = str_replace("{hits_title}",'',$l_Template);
  $l_Template = str_replace("{hits_value}",'',$l_Template);
  if (strpos($l_Template, "{screenshot_end}") > 0) {
    $pos_end = strpos($l_Template, '{screenshot_end}');
    $pos_beg = strpos($l_Template, '{screenshot_begin}');
    $l_Template = substr_replace($l_Template, '', $pos_beg, ($pos_end - $pos_beg) + 16);
  }
  $l_Template = str_replace("{thumbnail_lightbox}",'',$l_Template);
  $l_Template = str_replace("{thumbnail_gallery}",'',$l_Template);
  $l_Template = str_replace("{created_by_title}",'',$l_Template);
  $l_Template = str_replace("{created_by_value}",'',$l_Template);
  $l_Template = str_replace("{created_date_title}",'',$l_Template);
  $l_Template = str_replace("{created_date_value}",'',$l_Template);
  $l_Template = str_replace("{modified_by_title}",'',$l_Template);
  $l_Template = str_replace("{modified_by_value}",'',$l_Template);
  $l_Template = str_replace("{modified_date_title}",'',$l_Template);
  $l_Template = str_replace("{modified_date_value}",'',$l_Template);
  $l_Template = str_replace("{price_title}",'',$l_Template);
  $l_Template = str_replace("{price_value}",'',$l_Template);
  $l_Template = str_replace("{system_title}",'',$l_Template);
  $l_Template = str_replace("{system_text}",'',$l_Template);
  $l_Template = str_replace("{license_title}",'',$l_Template);
  $l_Template = str_replace("{license_text}",'',$l_Template);
  $l_Template = str_replace("{language_title}",'',$l_Template);
  $l_Template = str_replace("{language_text}",'',$l_Template);
  $l_Template = str_replace("{filesize_title}",'',$l_Template);
  $l_Template = str_replace("{filesize_value}",'',$l_Template);
  $l_Template = str_replace("{author}",'',$l_Template);
  $l_Template = str_replace("{url_author}",'',$l_Template);
  $l_Template = str_replace("{author_title}",'',$l_Template);
  $l_Template = str_replace("{author_text}",'',$l_Template);
  $l_Template = str_replace("{url_home}",'',$l_Template);
  $l_Template = str_replace("{author_url_title}",'',$l_Template);
  $l_Template = str_replace("{author_url_text}",'',$l_Template);

  return str_replace("[[[","{",$l_Template);
}

function jd_file_fill_downloadok($p_Template, $p_Frow, $p_Symbol_Off, $p_DownloadType, $p_dallowed){
  global $jlistConfigM, $jDFPitemid, $jDFPsfolders, $jDFPrank, $jDFPv14, $jDFPlive_site, $jDFPplugin_live_site, $jDFPabsolute_path, $mosConfig_live_site;

  $database = getDBO();

  $l_Template = str_replace("{{{","[[[",$p_Template);
  //Gйnйrer les mini-icфnes
  $jdpic_license = '';
  $jdpic_date = '';
  $jdpic_author = '';
  $jdpic_website = '';
  $jdpic_system = '';
  $jdpic_language = '';
  $jdpic_download = '';
  $jdpic_size = '';
  $jdpic_price = '';
  if ($p_Symbol_Off == 0){
    $msize = $jlistConfigM['info.icons.size'];
    $jdpic_license = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['mini'].'license.png" align="absmiddle" width="'.$msize.'" height="'.$msize.'" border="0" alt="" title="'._JLIST_FRONTEND_MINI_ICON_ALT_LICENCE.'" />&nbsp;';
    $jdpic_date = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['mini'].'date.png" align="absmiddle" width="'.$msize.'" height="'.$msize.'" border="0" alt="" title="'._JLIST_FRONTEND_MINI_ICON_ALT_DATE.'" />&nbsp;';
    $jdpic_author = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['mini'].'contact.png" align="absmiddle" width="'.$msize.'" height="'.$msize.'" border="0" alt="" title="'._JLIST_FRONTEND_MINI_ICON_ALT_AUTHOR.'" />&nbsp;';
    $jdpic_website = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['mini'].'weblink.png" align="absmiddle" width="'.$msize.'" height="'.$msize.'" border="0" alt="" title="'._JLIST_FRONTEND_MINI_ICON_ALT_WEBSITE.'" />&nbsp;';
    $jdpic_system = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['mini'].'system.png" align="absmiddle" width="'.$msize.'" height="'.$msize.'" border="0" alt="" title="'._JLIST_FRONTEND_MINI_ICON_ALT_SYSTEM.'" />&nbsp;';
    $jdpic_language = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['mini'].'language.png" align="absmiddle" width="'.$msize.'" height="'.$msize.'" border="0" alt="" title="'._JLIST_FRONTEND_MINI_ICON_ALT_LANGUAGE.'" />&nbsp;';
    $jdpic_download = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['mini'].'download.png" align="absmiddle" width="'.$msize.'" height="'.$msize.'" border="0" alt="" title="'._JLIST_FRONTEND_MINI_ICON_ALT_DOWNLOAD.'" />&nbsp;';
    $jdpic_size = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['mini'].'stuff.png" align="absmiddle" width="'.$msize.'" height="'.$msize.'" border="0" alt="" />&nbsp;';
    $jdpic_price = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['mini'].'currency.png" align="absmiddle" width="'.$msize.'" height="'.$msize.'" border="0" alt="" />&nbsp;';
  }
  $jdextern_url_pic = '<img src="'.$jDFPplugin_live_site.'content/mos_yfiles_file/images/link_extern.gif" />';

  $jd_file_pic = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['file'].$p_Frow->file_pic.'" align="absmiddle" border="0" height="'.$jlistConfigM['file.pic.size'].'" width="'.$jlistConfigM['file.pic.size'].'" alt="" />';
  $jd_cat_id = $p_Frow->cat_id;
  $jd_filename = $p_Frow->url_download;
  $jd_language = $p_Frow->language;
  $jd_system = $p_Frow->system;

  //Chercher catйgorie du fichier pour calculer le rйpertoire
  $cSQLquery = "SELECT * FROM #__yfiles_cats WHERE cat_id = ".$jd_cat_id;
  $database->setQuery($cSQLquery);
  $crows = $database->loadObjectList();

  // get license data and build link
  $jd_license = $p_Frow->license;
  $database->setQuery('SELECT * FROM #__yfiles_license WHERE id = '.$jd_license);
  $jdlic = $database->loadObjectList();
  $jd_filelicense = '';
  if (isset($jdlic[0])){
    if (!$jdlic[0]->license_url == '') {
      $jd_filelicense = $jdpic_license.'<a href="'.$jdlic[0]->license_url.'" target="_blank" title="'._JLIST_FRONTEND_MINI_ICON_ALT_LICENCE.'">'.$jdlic[0]->license_title.'</a> '.$jdextern_url_pic;
    } else {
      if (!$jdlic[0]->license_title == '') {
        $jd_filelicense = $jdpic_license.$ldlic[0]->license_title;
      } else {
        $jd_filelicense = '';
      }
    }
  }
  //Chercher la langue dans la config de Yfiles
  $file_lang_values = explode(',' , $jlistConfigM['language.list']);
  if ($jd_language == 0 ) {
    $jd_showlanguage = '';
  } else {
    $jd_showlanguage = $jdpic_language.$file_lang_values[$jd_language];
  }

  //Chercher le System dans la config de Yfiles
  $file_sys_values = explode(',' , $jlistConfigM['system.list']);
  if ($jd_system == 0 ) {
     $jd_showsystem = '';
  } else {
     $jd_showsystem = $jdpic_system.$file_sys_values[$jd_system];
  }

  //Calculer author URL
  if (!$p_Frow->url_home == '') {
     if (strpos($p_Frow->url_home, 'http://') === false){
         $jd_urlhome = $jdpic_website.'<a href="http://'.$p_Frow->url_home.'" target="_blank" title="'._JLIST_FRONTEND_HOMEPAGE.'">'._JLIST_FRONTEND_HOMEPAGE.'</a> '.$jdextern_url_pic;
     } else {
         $jd_urlhome = $jdpic_website.'<a href="'.$p_Frow->url_home.'" target="_blank" title="'._JLIST_FRONTEND_HOMEPAGE.'">'._JLIST_FRONTEND_HOMEPAGE.'</a> '.$jdextern_url_pic;
     }
  } else {
       $jd_urlhome = '';
  }

  // build author link
  $jd_mail_encode = '';
  if (!$p_Frow->author){
    $jd_author_name = '';
  } else {
    $jd_author_name = $p_Frow->author;
  }
  if ($p_Frow->url_author <> '') { // url_author is set
    if (strpos($p_Frow->url_author, '@')){ // url_author is email
      if ($jlistConfigM['mail.cloaking']){
        $jd_mail_encode = $jdpic_author.jd_emailcloak($p_Frow->url_author, $jd_author_name);
      } else {
        $jd_mail_encode = $jdpic_author.'<a href="mailto:'.$p_Frow->url_author.'">'.$jd_author_name.'</a>';
      }

    } else { // url_author is website
      if ($jd_author_name == ''){
        $jd_author_name = _JLIST_FRONTEND_HOMEPAGE;
      }
      if (strpos($p_Frow->url_author, 'http://') !== false) { // link has http
        $jd_mail_encode = $jdpic_website.'<a href="'.$p_Frow->url_author.'" target="_blank">'.$jd_author_name.'</a>';
      } else { // link has no http.
        $jd_mail_encode = $jdpic_website.'<a href="http://'.$p_Frow->url_author.'" target="_blank">'.$jd_author_name.'</a>';
      }
    }
  }
  if ($jd_mail_encode != '') {
    $jdlink_author_text = $jd_mail_encode.' '.$jdextern_url_pic;
  } else {
    $jdlink_author_text = $jd_author_name;
  }

  //Calculer URL-Download
  $jd_url_download_file = jd_SefRel('index.php?option=com_yfiles&amp;Itemid='.$jDFPitemid.'&amp;task=finish&cid='.$p_Frow->file_id.'&catid='.$jd_cat_id);
  if (trim($p_Frow->extern_file) != ''){
    $jd_url_download_durl = $p_Frow->extern_file;
  } else {
  $jd_url_download_durl = $jDFPlive_site.$jlistConfigM['files.uploaddir']."/".$crows[0]->cat_dir."/".$jd_filename;
  }

  if ($p_DownloadType == 'durl') {
    $jd_url_download_link = $jd_url_download_durl;
  } else {
    $jd_url_download_link = $jd_url_download_file;
  }

  if ($p_dallowed == 1){
  $jd_url_download = $jdpic_download.'<a href="'.$jd_url_download_link.'">'._JLIST_LINKTEXT_DOWNLOAD_URL.'</a>';
  }
  else{
    $jd_url_download = $jdpic_download._JLIST_LINKTEXT_DOWNLOAD_URL;
  }

  $jd_downloadpict = "<img src=\"".$jDFPplugin_live_site."content/mos_yfiles_file/images/download.gif\" border = \"0\" alt=\"\" />";

  if ($p_dallowed == 1){
    $jd_download = '<a href="'.$jd_url_download_link.'">'.$jd_downloadpict.'</a>';
  }
  else {
	$jd_download = $jd_downloadpict;
  }

  //Calculer link to details
  $jd_titel_link = jd_SefRel('index.php?option=com_yfiles&amp;Itemid='.$jDFPitemid.'&amp;task=view.download&cid='.$p_Frow->file_id);
  $jd_detail_link_text = '<a href="'.$jd_titel_link.'">'._JLIST_FE_DETAILS_LINK_TEXT_TO_DETAILS.'</a>';
  $jd_title_link = '<a href="'.$jd_titel_link.'">'.$p_Frow->file_title.'</a>';

  //Calculer mirror1
  $jd_mirror1_link = '';
  if ($p_Frow->mirror_1) {
    if ($p_DownloadType == 'durl') {
      $jd_mirror1_link = '<a href="'.$p_Frow->mirror_1.'">'._JLIST_FRONTEND_MIRROR_URL_TITLE_1.'</a>';
    } else {
      $jd_mirror1 = $jd_url_download_file.'&m=1';
      $jd_mirror1_link = '<a href="'.$jd_mirror1.'">'._JLIST_FRONTEND_MIRROR_URL_TITLE_1.'</a>';
    }
    if ($p_dallowed == 0){
    	$jd_mirror1_link = _JLIST_FRONTEND_MIRROR_URL_TITLE_1;
    }
  }

  //Calculer mirror2
  $jd_mirror2_link = '';
  if ($p_Frow->mirror_2) {
    if ($p_DownloadType == 'durl') {
      $jd_mirror2_link = '<a href="'.$p_Frow->mirror_2.'">'._JLIST_FRONTEND_MIRROR_URL_TITLE_2.'</a>';
    } else {
      $jd_mirror2 = $jd_url_download_file.'&m=2';
      $jd_mirror2_link = '<a href="'.$jd_mirror2.'">'._JLIST_FRONTEND_MIRROR_URL_TITLE_2.'</a>';
    }
    if ($p_dallowed == 0){
    	$jd_mirror2_link = _JLIST_FRONTEND_MIRROR_URL_TITLE_2;
    }
  }

  //Calculer symbole HOT
  if ($jlistConfigM['loads.is.file.hot'] > 0 && $p_Frow->downloads >= $jlistConfigM['loads.is.file.hot']){
     $jd_hotpic = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['hot'].$jlistConfigM['picname.is.file.hot'].'" alt="" />';
  } else {
     $jd_hotpic = "";
  }

  //Calculer symbole NEW
  $jours_diff = DatumsDifferenz_JDm(date('Y-m-d H:m:s'), $p_Frow->date_added);
  if ($jlistConfigM['days.is.file.new'] > 0 && $jours_diff <= $jlistConfigM['days.is.file.new']){
     $jd_newpic = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['new'].$jlistConfigM['picname.is.file.new'].'" alt="" />';

  } else {
     $jd_newpic = "";
  }

  //Calculer la date de modification du fichier
  if ($p_Frow->modified_date != '0000-00-00 00:00:00') {
     $jdmodified_data = $jdpic_date.substr(jd_DateForm($p_Frow->modified_date, $jlistConfigM['global.datetime'], $offset = NULL),0,10);
  } else {
     $jdmodified_data = '';
  }

  //Calculer la date du fichier
   $jd_showdate = $jdpic_date.substr(jd_DateForm($p_Frow->date_added),0,10);

  //Calculer la taille du fichier
  $jd_showsize = '';
  if (trim($p_Frow->size) != '') {
    $jd_showsize = $jdpic_size.$p_Frow->size;
  }

  //Calculer le prix
  $jd_showprice = '';
  if (trim($p_Frow->price) != '') {
    $jd_showprice = $jdpic_price.$p_Frow->price;
  }

  //Calculer la release
  $jd_showrelease = '';
  if (trim($p_Frow->release) != '') {
    $jd_showrelease = _JLIST_FRONTEND_VERSION_TITLE.$p_Frow->release;
  }

  //Formater output
  $l_Template = str_replace("{file_pic}",$jd_file_pic,$l_Template);
  $l_Template = str_replace("{file_title_only}",$p_Frow->file_title,$l_Template);
  $l_Template = str_replace("{file_title}",$jd_title_link,$l_Template);
  $l_Template = str_replace("{description}",$p_Frow->description,$l_Template);
  $l_Template = str_replace("{release}",$jd_showrelease,$l_Template);
  $l_Template = str_replace("{size}",$jd_showsize,$l_Template);
  $l_Template = str_replace("{filesize_value}",$jd_showsize,$l_Template);
  $l_Template = str_replace("{downloads}",$p_Frow->downloads,$l_Template);
  $l_Template = str_replace("{hits_value}",$p_Frow->downloads,$l_Template);
  $l_Template = str_replace("{pic_is_new}",$jd_newpic,$l_Template);
  $l_Template = str_replace("{pic_is_hot}",$jd_hotpic,$l_Template);
  $l_Template = str_replace("{license}",$jd_filelicense,$l_Template);
  $l_Template = str_replace("{license_text}",$jd_filelicense,$l_Template);
  $l_Template = str_replace("{author}",$jdlink_author_text,$l_Template);
  $l_Template = str_replace("{author_text}",$jdlink_author_text,$l_Template);
  $l_Template = str_replace("{url_author}",'',$l_Template);
  $l_Template = str_replace("{url_home}",$jd_urlhome,$l_Template);
  $l_Template = str_replace("{author_url_text}",$jd_urlhome,$l_Template);
  $l_Template = str_replace("{date_added}",$jd_showdate,$l_Template);
  $l_Template = str_replace("{created_date_value}",$jd_showdate,$l_Template);
  $l_Template = str_replace("{language}",$jd_showlanguage,$l_Template);
  $l_Template = str_replace("{language_text}",$jd_showlanguage,$l_Template);
  $l_Template = str_replace("{system}",$jd_showsystem,$l_Template);
  $l_Template = str_replace("{system_text}",$jd_showsystem,$l_Template);
  $l_Template = str_replace("{checkbox_list}",$jd_download,$l_Template);
  $l_Template = str_replace("{url_download}",$jd_url_download,$l_Template);
  $l_Template = str_replace("{file_id}",$p_Frow->file_id,$l_Template);
  $l_Template = str_replace("{ordering}",$p_Frow->ordering,$l_Template);
  $l_Template = str_replace("{published}",$p_Frow->published,$l_Template);
  $l_Template = str_replace("{cat_id}",$p_Frow->cat_id,$l_Template);
  $l_Template = str_replace("{price_value}",$jd_showprice,$l_Template);
  $l_Template = str_replace("{link_to_details}",$jd_detail_link_text,$l_Template);
  $l_Template = str_replace("{mirror_1}",$jd_mirror1_link,$l_Template);
  $l_Template = str_replace("{mirror_2}",$jd_mirror2_link,$l_Template);
  $l_Template = str_replace("{rank}",$jDFPrank,$l_Template);


  // new for V 1.4

  if (strpos($l_Template, "{files_title_end}") > 0){
    $pos_end = strpos($l_Template, '{files_title_end}');
    $pos_beg = strpos($l_Template, '{files_title_begin}');
    $l_Template = substr_replace($l_Template, '', $pos_beg, ($pos_end - $pos_beg) + 17);
  }

  if ($jDFPv14 > 0){

    $jd_thumbnail = '';
    $jd_screenshot = '';
    $jd_updatedpic = '';

    // Calculer Thumbnail and Screenshot
    $jd_thumbnail = $jDFPsfolders['thumb']."no_pic.gif";
    $jd_screenshot = $jDFPsfolders['screenshot']."no_pic.gif";
    $jd_thumbfile = $jDFPabsolute_path.$jDFPsfolders['thumb'].$p_Frow->thumbnail;
    $jd_screenfile = $jDFPabsolute_path.$jDFPsfolders['screenshot'].$p_Frow->thumbnail;
    if (file_exists($jd_thumbfile) && file_exists($jd_screenfile) && $p_Frow->thumbnail != '') {
      $jd_thumbnail = $mosConfig_live_site.'/'.$jDFPsfolders['thumb'].$p_Frow->thumbnail;
      $jd_screenshot = $mosConfig_live_site.'/'.$jDFPsfolders['screenshot'].$p_Frow->thumbnail;
      $l_Template = str_replace("{thumbnail}",$jd_thumbnail,$l_Template);
      $l_Template = str_replace("{screenshot}",$jd_screenshot,$l_Template);
      $l_Template = str_replace('{screenshot_end}', '', $l_Template);
      $l_Template = str_replace('{screenshot_begin}', '', $l_Template);
      $jd_lightbox = '<a rel="lightbox" "href="'.$jd_screenshot.'"><img src="'.$jd_thumbnail.'" /></a>';
      $l_Template = str_replace('{thumbnail_lightbox}', $jd_lightbox, $l_Template);
      $jd_lightgallery = '<a title="'.$p_Frow->file_title.'" rel="lightbox[thegallery]" "href="'.$jd_screenshot.'"><img src="'.$mosConfig_live_site.'/'.$jd_thumbnail.'" alt="'.$p_Frow->file_title.'" /></a>';
      $l_Template = str_replace('{thumbnail_gallery}', $jd_lightgallery, $l_Template);

    } else {
      if ($jlistConfigM["thumbnail.view.placeholder.in.lists"] == 1){
        $l_Template = str_replace("{thumbnail}",$jd_thumbnail,$l_Template);
        $l_Template = str_replace("{screenshot}",$jd_screenshot,$l_Template);
        $l_Template = str_replace('{screenshot_end}', '', $l_Template);
        $l_Template = str_replace('{screenshot_begin}', '', $l_Template);
        $jd_lightbox = '<a rel="lightbox" "href="'.$jd_screenshot.'"><img src="'.$jd_thumbnail.'" /></a>';
        $l_Template = str_replace('{thumbnail_lightbox}', $jd_lightbox, $l_Template);
        $jd_lightgallery = '<a title="'.$p_Frow->file_title.'" rel="lightbox[thegallery]" "href="'.$jd_screenshot.'"><img src="'.$mosConfig_live_site.'/'.$jd_thumbnail.'" alt="'.$p_Frow->file_title.'" /></a>';
        $l_Template = str_replace('{thumbnail_gallery}', $jd_lightgallery, $l_Template);
      } else {
        $l_Template = str_replace('{thumbnail_lightbox}', '', $l_Template);
        $l_Template = str_replace('{thumbnail_gallery}', '', $l_Template);
        if (strpos($l_Template, "{screenshot_end}") > 0) {
          $pos_end = strpos($l_Template, '{screenshot_end}');
          $pos_beg = strpos($l_Template, '{screenshot_begin}');
          $l_Template = substr_replace($l_Template, '', $pos_beg, ($pos_end - $pos_beg) + 16);
        }
      }
    }

   //Calculate symbol UPDATED
    $jours_diff = DatumsDifferenz_JDm(date('Y-m-d H:m:s'), $p_Frow->modified_date);
    if ($jlistConfigM['days.is.file.updated'] > 0 && $jours_diff <= $jlistConfigM['days.is.file.updated']){
      $jd_updatedpic = '<img src="'.$mosConfig_live_site.'/'.$jDFPsfolders['upd'].$jlistConfigM['picname.is.file.updated'].'" alt=""/>';
    } else {
      $jd_updatedpic = "";
    }
    $l_Template = str_replace("{pic_is_updated}",$jd_updatedpic,$l_Template);

    // Some other new values in 1.4
    $l_Template = str_replace("{modified_date_value}",$jdmodified_data,$l_Template);
    $l_Template = str_replace('{created_by_value}',$p_Frow->created_by, $l_Template);
    $l_Template = str_replace('{modified_by_value}',$p_Frow->modified_by, $l_Template);

    // New placeholders in 1.4
    $l_Template = str_replace('{license_title}', _JLIST_FE_FILELIST_LICENSE_TITLE, $l_Template);
    $l_Template = str_replace('{price_title}', _JLIST_FE_FILELIST_PRICE_TITLE, $l_Template);
    $l_Template = str_replace('{language_title}', _JLIST_FE_FILELIST_LANGUAGE_TITLE, $l_Template);
    $l_Template = str_replace('{filesize_title}', _JLIST_FE_FILELIST_FILESIZE_TITLE, $l_Template);
    $l_Template = str_replace('{system_title}', _JLIST_FE_FILELIST_SYSTEM_TITLE, $l_Template);
    $l_Template = str_replace('{author_title}', _JLIST_FE_FILELIST_AUTHOR_TITLE, $l_Template);
    $l_Template = str_replace('{author_url_title}', _JLIST_FE_FILELIST_AUTHOR_URL_TITLE, $l_Template);
    $l_Template = str_replace('{created_date_title}', _JLIST_FE_FILELIST_CREATED_DATE_TITLE, $l_Template);
    $l_Template = str_replace('{hits_title}', _JLIST_FE_FILELIST_HITS_TITLE, $l_Template);
    $l_Template = str_replace('{created_by_title}', _JLIST_FE_FILELIST_CREATED_BY_TITLE, $l_Template);
    $l_Template = str_replace('{modified_by_title}', _JLIST_FE_FILELIST_MODIFIED_BY_TITLE, $l_Template);
    $l_Template = str_replace('{modified_date_title}', _JLIST_FE_FILELIST_MODIFIED_DATE_TITLE, $l_Template);
  }
  return str_replace("[[[","{",$l_Template);
}
?>